package com.dkd.day20250616;

import java.util.Stack;

public class SolutionMin {
    public static void main(String[] args) {

    }

    //原栈
    Stack<Integer> s1 = new Stack();
    //记录最小栈
    Stack<Integer> s2 = new Stack();

    public void push(int node) {
        s1.push(node);
        //如果小于原来的就添加，不小于就加入顶，保持栈数量一致
        if(s2.isEmpty() || s2.peek() > node) {
            s2.push(node);
        }else s2.push(s2.peek());

    }

    public void pop() {
        s1.pop();
        s2.pop();
    }

    public int top() {
        return s1.peek();
    }

    public int min() {
        return s2.peek();
    }
}
